import { reactive, computed } from 'vue'
import { ColumnProps } from "ant-design-vue/es/table/interface";
type Key = ColumnProps["key"];
interface DataType {
    id: string
}
export default function useUserRepositories() {
    const state = reactive<{
        selectedRowKeys: Key[];
        loading: boolean;
        removeId: string;
        currItem: any;
    }>({
        selectedRowKeys: [],
        loading: false,
        removeId: '',
        currItem: {}
    });
    const hasSelected = computed(() => state.selectedRowKeys.length > 0);
    const hasSelectedModify = computed(() => state.selectedRowKeys.length === 1);
    const onSelectChange = (selectedRowKeys: Key[], selectedRows: DataType[]) => {
        state.selectedRowKeys = selectedRowKeys;
        state.currItem = selectedRows[0];
        state.removeId = selectedRows.map((item) => item.id).join(',');
    };
    return {
        state,
        hasSelected,
        onSelectChange,
        hasSelectedModify
    }
}